/*
 * @Author: liuxinyea
 * @Date: 2024-08-11 22:24:54
 * @LastEditors: liuxinyea
 * @LastEditTime: 2024-08-11 22:59:08
 * @Description: 描述
 */
import { _decorator, animation, CCInteger, Component, find, instantiate, Node, Prefab } from 'cc';
import { Plant } from '../Plant';
import { PlantType } from '../Glabol';
const { ccclass, property } = _decorator;

@ccclass('Sunflower')
export class Sunflower extends Plant {
    public plantType: PlantType = PlantType.Sunflower;
    @property(CCInteger)
    produceDuration: number = 5;
    private produceTimer: number = 0;
    private deltaTime: number
    private anim:animation.AnimationController;
    @property(Prefab)
    sunPrefab: Prefab = null;
    protected onLoad(): void {
        this.anim = this.getComponent(animation.AnimationController);
    }
    update(deltaTime: number): void {
        super.update(deltaTime);
        this.deltaTime = deltaTime;
    }
    // 种下去之后再激活
    enableUpdate() {
       super.enableUpdate()
        this.produceTimer += this.deltaTime;
        if(this.produceTimer >= this.produceDuration){
            this.anim.setValue("isGrown",true);
            this.produceTimer = 0;
        }
    }
    BurnSun() {
        console.log("BurnSun");
        const sun = instantiate(this.sunPrefab)
        sun.setPosition(this.node.position)
        sun.parent = find("Canvas/ForGround")
    }
}

